<?php
namespace Infinity;

abstract class Arr {
  public static function recursiveMap(&$array, $callback) {
    if($callback($array))
      return true;
    foreach($array as $key => $element) {
      if(is_array($element)) {
        if(self::recursiveMap($array[$key], $callback))
          return true;
      }
    }
    return false;
  }

  /**
   * 數組插入數據在$myarray数组的$position处插入$value
   * @param $myarray
   * @param $value
   * @param int $position
   * @return array
   */
  public static function array_insert($myarray, $value, $position = 0) {
    $fore = ($position == 0) ? array() : array_splice($myarray, 0, $position);
    $fore[] = $value;
    $ret = array_merge($fore, $myarray);
    return $ret;
  }

  public static function remove(array $array, $value) {
    foreach($array as $key => $arr) {
      if($arr == $value)
        unset($array[$key]);
    }
    return $array;
  }
}